/*
 * $Id$
 */
package corejs;

import corejs.parser.InfixParser;
import corejs.parser.PrefixParser;
import corejs.parser.StatementParser;

/**
 *
 * @author myang
 */
public class Token {

   public static final Token EOF = new Token(JsTokenType.EOF, "EOF");

   protected String _text;
   protected int _lineNum;
   protected int _col;
   protected TokenType _type;

   protected Token(final TokenType type, final String text) {
      _type = type;
      _text = text;
   }

   public PrefixParser getPrefixParser() {
      return _type == null ? null : _type.prefix();
   }

   public InfixParser getInfixParser() {
      return _type == null ? null : _type.infix();
   }

   public StatementParser getStatementParser() {
      return _type == null ? null : _type.statement();
   }

   public String text() {
      return _text;
   }

   public TokenType type() {
      return _type;
   }

   public int col() {
      return _col;
   }

   public int lineNum() {
      return _lineNum;
   }

   public Token lineNum(final int lineNum) {
      _lineNum = lineNum;
      return this;
   }

   public Token col(final int col) {
      _col = col;
      return this;
   }

   public boolean is(final TokenType type) {
      return _type == type;
   }

   @Override
   public String toString() {
      return String.format("%4d:%3d:%s:%s", _lineNum, _col, _type, _text);
   }
}
